package com.zz.ecommerce.searchManage.logsitics;

import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.constants.TableConstants;
import com.zz.ecommerce.declareManage.common.service.QdcOrderService;
import com.zz.ecommerce.logisticsManage.search.LogisticsMgnDao;
import com.zz.ecommerce.logisticsManage.search.LogisticsStatusMgnDao;
import com.zz.ecommerce.pojo.CbecLogistics;
import com.zz.ecommerce.pojo.CbecLogisticsStatus;
import com.zz.ecommerce.utils.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 物流状态查询
 */
@Controller
@RequestMapping("searchManage/logsitics")
public class LogsiticsSearchController {

    @Autowired
    LogsiticsService logsiticsService;

    /**
     * 跳转到初始化查询页面
     *
     * @return
     */
    @RequestMapping("/init")
    public String init() {
        return "searchManage/logsitics/index";
    }

    /**
     * 查询物流状态
     *
     * @param request
     * @return
     */
    @RequestMapping("/queryLogsiticsStatus")
    @ResponseBody
    public GridResult queryLogsiticsStatus(GridRequest request, TWaybillHeadQdc tWaybillHeadQdc) {
        return logsiticsService.queryLogsiticsStatus(request, tWaybillHeadQdc);
    }


    @Autowired
    private QdcOrderService orderService;
    @Autowired
    private LogisticsStatusMgnDao logisticsStatusMgnDao;

    @Autowired
    private LogisticsMgnDao logisticsMgnDao;



    @RequestMapping(value = "index", method = {RequestMethod.GET, RequestMethod.POST})
    public String index() {
        return "searchManage/logsitics/logsitics_index";
    }

//    @RequestMapping("/queryOrderList")
//    @ResponseBody
//    public GridResult queryOrderList(LogisticsOrderQdc orderHead, GridRequest request, HttpSession session) {
//       orderHead.setOrgId(SessionUtil.getOrganizationId(session));
//        return orderService.queryOrderListEq(request, orderHead);
//    }
    @RequestMapping("/queryOrderList")
    @ResponseBody
    public GridResult queryOrderList(CbecLogistics cbecLogistics, GridRequest request, HttpSession session) {
        cbecLogistics.setOrgId(SessionUtil.getOrganizationId(session));
        List<CbecLogistics> tPersonalIdentities = logisticsMgnDao.page(TableConstants.CBEC_LOGISTICS, cbecLogistics,
                request.getStart(), request.getEnd(), request.getSortOrder());
        return new GridResult<CbecLogistics>(tPersonalIdentities, request, logisticsMgnDao.count(TableConstants.CBEC_LOGISTICS, cbecLogistics));
    }

    @RequestMapping("/showDetail")
    public String showDetail(CbecLogisticsStatus cbecLogisticsStatusList, ModelMap modelMap) {
        List<CbecLogisticsStatus> cbecLogisticsStatuses = logisticsStatusMgnDao.queryAll(TableConstants.CBEC_LOGISTICS_STATUS, cbecLogisticsStatusList, " logistics_date DESC ");
        modelMap.addAttribute("cbecLogisticsStatuses", cbecLogisticsStatuses);
        return "logisticsManage/search/logistics_detail";
    }

    public static class Logsitics {

        private String type;
        private String no;
        private String mark;
        private String detail;

        public String getDetail() {
            return this.detail;
        }

        public void setDetail(final String detail) {
            this.detail = detail;
        }

        public String getType() {
            return this.type;
        }

        public void setType(final String type) {
            this.type = type;
        }

        public String getNo() {
            return this.no;
        }

        public void setNo(final String no) {
            this.no = no;
        }

        public String getMark() {
            return this.mark;
        }

        public void setMark(final String mark) {
            this.mark = mark;
        }
    }
}
